﻿using System;
using System.Text;
using System.Collections.Generic;

namespace Vision.Web.Common
{
    /// <summary>
    /// 
    /// </summary>
    public class QStringBuilder
    {
        /// <summary>
        /// 
        /// </summary>
        public QStringBuilder()
        {
            this.Path = string.Empty;
            this.Parameters = new Dictionary<string, string>();
        }

        /// <summary>
        /// 
        /// </summary>
        public string Path { get; set; }
                
        /// <summary>
        /// 
        /// </summary>
        public Dictionary<string, string> Parameters { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string QueryString
        {
            get {
                StringBuilder qsBuilder = new StringBuilder();
                qsBuilder.Append(this.Path);
                int count = 0;
                foreach (string key in this.Parameters.Keys){
                    if (count == 0){
                        qsBuilder.Append("?");
                    }
                    else{
                        qsBuilder.Append("&");
                    }
                    qsBuilder.Append(System.Web.HttpUtility.UrlEncode(key));
                    qsBuilder.Append("=");
                    qsBuilder.Append(System.Web.HttpUtility.UrlEncode(this.Parameters[key]));
                    count++;
                }                
                return qsBuilder.ToString();
            }            
        }
    }    
}